// Token管理工具函数
export const tokenUtils = {
  // 保存token到本地存储
  saveTokens: (accessToken, refreshToken) => {
    localStorage.setItem('accessToken', accessToken)
    localStorage.setItem('refreshToken', refreshToken)
  },

  // 获取token
  getAccessToken: () => {
    return localStorage.getItem('accessToken')
  },

  getRefreshToken: () => {
    return localStorage.getItem('refreshToken')
  },

  // 清除token
  clearTokens: () => {
    localStorage.removeItem('accessToken')
    localStorage.removeItem('refreshToken')
  },

  // 检查是否已登录
  isLoggedIn: () => {
    return !!localStorage.getItem('accessToken')
  }
}

// 用户数据工具函数
export const userUtils = {
  // 保存用户信息
  saveUser: (user) => {
    localStorage.setItem('user', JSON.stringify(user))
  },

  // 获取用户信息
  getUser: () => {
    const user = localStorage.getItem('user')
    return user ? JSON.parse(user) : null
  },

  // 清除用户信息
  clearUser: () => {
    localStorage.removeItem('user')
  }
}
